home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cc02.arc / FIBO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-03-15  |  600 b   |  41 lines

  1. /* -- fibo.c  fibonacci series benchmark -- */
  2.  
  3. #include "stdio.h"
  4.  
  5. #define NTIMES 10        /* number of times to compute fibonacci value */
  6. #define NUMBER 24        /* biggest one we can compute within 16 bits */
  7.  
  8. main() {
  9.  
  10.     int i;
  11.     unsigned value, fib();
  12.  
  13.     printf("%d iterations: ", NTIMES);
  14.  
  15.     for (i = 1; i <= NTIMES; i++)
  16.         value = fib(NUMBER);
  17.  
  18.     printf("fibonacci(%d) = %u.\n", NUMBER, value);
  19.     exit(0);
  20.  
  21. }
  22.  
  23. unsigned fib(x)         /* compute fibonacci number recursively */
  24.  
  25.     int x;
  26.  
  27.     {
  28.         if (x > 2)
  29.             return (fib(x - 1) + fib(x - 2));
  30.         else
  31.             return (1);
  32.     }
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.